package com.ruoyi.client.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.client.mapper.BookShelfMapper;
import com.ruoyi.client.pojo.vo.BookShelfVo;
import com.ruoyi.client.service.BookShelfService;
import com.sun.jna.platform.win32.Winspool;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookShelfServiceImpl implements BookShelfService {

    @Resource
    private BookShelfMapper shelfMapper;
    @Override
    public List<BookShelfVo> list(Long userId) {
        return shelfMapper.list(userId);
    }

    @Override
    public boolean addBookShelf(BookShelfVo bookShelfVo) {
        //购物车中商品不能有重复项
        BookShelfVo bookShelfVo1=shelfMapper.selectByUserIdAndNovelId(bookShelfVo.getUserId(), bookShelfVo.getNovelId());
        if (bookShelfVo1 == null){
            return shelfMapper.addBookShelf(bookShelfVo)>0;

        }else{
            return false;
        }
    }

    @Override
    public boolean deleteBookshelf(String ids) {
        long[] idArray;
        idArray= StrUtil.splitToLong(ids,",");
        return shelfMapper.deleteBookshelf(idArray);
    }

    @Override
    public boolean update(BookShelfVo bookShelfVo) {
        return shelfMapper.update(bookShelfVo)>0;
    }

    @Override
    public boolean updateCheckAll(Long userId, Boolean isCheck) {
        Integer checked= isCheck ? 1 :0;
        return shelfMapper.updateCheckAll(userId, checked)>0;
    }

    @Override
    public List<BookShelfVo> listCheck(Long userId) {
        return shelfMapper.listCheck(userId);
    }

    @Override
    public boolean deleteAll(Long userId) {
        return shelfMapper.deleteAll(userId);
    }


}
